# added by yinchao, Tue July 02 08:43	2024
# 处理 mysql 的插入语句, 使之符合新的表的结构定义

import re

with open('deck_tb.sql', 'r', encoding='utf-8') as f, open('deck_tb2.sql', 'w', encoding='utf-8') as retf:
    id = 0
    for line in f:
        final_str = line
        pattern = '\((.*?)\)'
        matches = re.findall(pattern, line)
        if len(matches) > 0:
            s = matches[0]
            ret = s.split(',')
            if len(ret) >= 7:
                del ret[-1]
                del ret[-2]
                del ret[-3]
                del ret[0]

                id += 1
                new_s = ', '.join(ret)
                new_s = new_s.replace(' ', '')
                final_str = re.sub(pattern, f'({id},{new_s})', line)

        retf.write(final_str.replace('\\"', '"'))
